/*   1:    */ package com.rinsi.core.contoller;
/*   2:    */ 
/*   3:    */ import com.rinsi.core.service.CoreSimpleService;
/*   4:    */ import com.rinsi.util.CodeUtil;
/*   5:    */ import com.rinsi.util.FileUtil;
/*   6:    */ import com.rinsi.util.MapUtil;
/*   7:    */ import com.rinsi.util.SpringContextUtil;
/*   8:    */ import java.io.BufferedInputStream;
/*   9:    */ import java.io.File;
/*  10:    */ import java.io.FileInputStream;
/*  11:    */ import java.io.PrintWriter;
/*  12:    */ import java.net.URLDecoder;
/*  13:    */ import java.util.List;
/*  14:    */ import java.util.Map;
/*  15:    */ import javax.servlet.ServletOutputStream;
/*  16:    */ import javax.servlet.http.HttpServletRequest;
/*  17:    */ import javax.servlet.http.HttpServletResponse;
/*  18:    */ import org.apache.log4j.Logger;
/*  19:    */ import org.springframework.ui.ModelMap;
/*  20:    */ import org.springframework.web.bind.annotation.RequestMapping;
/*  21:    */ import org.springframework.web.bind.annotation.RequestParam;
/*  22:    */ import org.springframework.web.bind.annotation.ResponseBody;
/*  23:    */ import org.springframework.web.multipart.MultipartFile;
/*  24:    */ 
/*  25:    */ public abstract class CoreSimpleController
/*  26:    */   extends CoreController
/*  27:    */ {
/*  28: 50 */   private static Logger logger = Logger.getLogger(CoreSimpleController.class);
/*  29:    */   
/*  30:    */   @RequestMapping({"/list"})
/*  31:    */   public Map<String, Object> list(ModelMap model, HttpServletRequest request)
/*  32:    */   {
/*  33: 63 */     model.putAll(servce().list(model));
/*  34: 65 */     if (logger.isDebugEnabled()) {
/*  35: 67 */       logger.debug("list结果集信息：" + MapUtil.json(model));
/*  36:    */     }
/*  37: 71 */     return model;
/*  38:    */   }
/*  39:    */   
/*  40:    */   public Map<String, Object> item(ModelMap model, HttpServletRequest request)
/*  41:    */   {
/*  42: 85 */     model.putAll(servce().item(model));
/*  43: 87 */     if (logger.isDebugEnabled()) {
/*  44: 89 */       logger.debug("item结果集信息：" + MapUtil.json(model));
/*  45:    */     }
/*  46: 93 */     return model;
/*  47:    */   }
/*  48:    */   
/*  49:    */   @RequestMapping({"/save"})
/*  50:    */   public Map<String, Object> save(ModelMap model, HttpServletRequest request)
/*  51:    */   {
/*  52:108 */     model.putAll(servce().save(model));
/*  53:110 */     if (logger.isDebugEnabled()) {
/*  54:112 */       logger.debug("save信息：" + MapUtil.json(model));
/*  55:    */     }
/*  56:116 */     return model;
/*  57:    */   }
/*  58:    */   
/*  59:    */   @RequestMapping({"/del"})
/*  60:    */   public Map<String, Object> del(ModelMap model, HttpServletRequest request)
/*  61:    */   {
/*  62:131 */     model.putAll(servce().del(model));
/*  63:133 */     if (logger.isDebugEnabled()) {
/*  64:135 */       logger.debug("del信息：" + MapUtil.json(model));
/*  65:    */     }
/*  66:139 */     return model;
/*  67:    */   }
/*  68:    */   
/*  69:    */   @RequestMapping({"/lock"})
/*  70:    */   public Map<String, Object> lock(ModelMap model, HttpServletRequest request)
/*  71:    */   {
/*  72:154 */     model.putAll(servce().lock(model));
/*  73:156 */     if (logger.isDebugEnabled()) {
/*  74:158 */       logger.debug("lock信息：" + MapUtil.json(model));
/*  75:    */     }
/*  76:162 */     return model;
/*  77:    */   }
/*  78:    */   
/*  79:    */   @RequestMapping({"/unlock"})
/*  80:    */   public Map<String, Object> unlock(ModelMap model, HttpServletRequest request)
/*  81:    */   {
/*  82:177 */     model.putAll(servce().unlock(model));
/*  83:179 */     if (logger.isDebugEnabled()) {
/*  84:181 */       logger.debug("unlock信息：" + MapUtil.json(model));
/*  85:    */     }
/*  86:185 */     return model;
/*  87:    */   }
/*  88:    */   
/*  89:    */   @RequestMapping({"/fileList"})
/*  90:    */   public Map<String, Object> fileList(ModelMap model, HttpServletRequest request)
/*  91:    */   {
/*  92:197 */     Map<String, Object> rMap = servce().getRMap();
/*  93:    */     try
/*  94:    */     {
/*  95:201 */       Map<String, Object> params = servce().getParams(model);
/*  96:    */       
/*  97:203 */       String mod = MapUtil.getString((Map)model.get("module"), "MODULE_NO");
/*  98:    */       
/*  99:205 */       String filepath = (String)((Map)SpringContextUtil.getBean("config")).get("filepath") + mod + "/";
/* 100:    */       
/* 101:207 */       String ID = request.getParameter("ID") + "/";
/* 102:    */       
/* 103:209 */       filepath = filepath + ID;
/* 104:    */       
/* 105:211 */       List<Map<String, Object>> files = FileUtil.getFileList(filepath);
/* 106:    */       
/* 107:213 */       params.put("MODULE_NO", mod);
/* 108:    */       
/* 109:215 */       model.putAll(params);
/* 110:    */       
/* 111:217 */       model.put("files", files);
/* 112:    */       
/* 113:219 */       model.put("viewPage", "/commons/commons_filelist.jsp");
/* 114:    */     }
/* 115:    */     catch (Exception e)
/* 116:    */     {
/* 117:223 */       rMap.put("success", Boolean.valueOf(false));
/* 118:    */       
/* 119:225 */       rMap.put("message", e.getMessage());
/* 120:    */     }
/* 121:229 */     if (logger.isDebugEnabled()) {
/* 122:231 */       logger.debug("fileList信息：" + MapUtil.json(model));
/* 123:    */     }
/* 124:235 */     return rMap;
/* 125:    */   }
/* 126:    */   
/* 127:    */   @ResponseBody
/* 128:    */   @RequestMapping({"/upload"})
/* 129:    */   public void upload(@RequestParam MultipartFile file, HttpServletRequest request, HttpServletResponse response)
/* 130:    */   {
/* 131:    */     try
/* 132:    */     {
/* 133:250 */       String mod = request.getParameter("MODULE_NO") + "/";
/* 134:    */       
/* 135:252 */       String filepath = (String)((Map)SpringContextUtil.getBean("config")).get("filepath") + mod + "/";
/* 136:    */       
/* 137:254 */       String ID = request.getParameter("ID") + "/";
/* 138:    */       
/* 139:256 */       filepath = filepath + ID;
/* 140:    */       
/* 141:258 */       FileUtil.createFile(filepath, file.getOriginalFilename(), file.getBytes());
/* 142:    */       
/* 143:260 */       response.setCharacterEncoding("UTF-8");
/* 144:    */       
/* 145:262 */       response.getWriter().print(file.getOriginalFilename());
/* 146:    */     }
/* 147:    */     catch (Exception e)
/* 148:    */     {
/* 149:266 */       e.printStackTrace();
/* 150:    */     }
/* 151:    */   }
/* 152:    */   
/* 153:    */   @ResponseBody
/* 154:    */   @RequestMapping({"/fileRemove"})
/* 155:    */   public Map<String, Object> fileRemove(@RequestParam String filename, HttpServletRequest request, HttpServletResponse response)
/* 156:    */   {
/* 157:279 */     Map<String, Object> rMap = servce().getRMap();
/* 158:    */     try
/* 159:    */     {
/* 160:283 */       String mod = request.getParameter("MODULE_NO") + "/";
/* 161:    */       
/* 162:285 */       String filepath = (String)((Map)SpringContextUtil.getBean("config")).get("filepath") + mod + "/";
/* 163:    */       
/* 164:287 */       String ID = request.getParameter("ID") + "/";
/* 165:    */       
/* 166:289 */       filepath = filepath + ID;
/* 167:    */       
/* 168:291 */       FileUtil.deleteExistedFile(filepath, filename);
/* 169:    */     }
/* 170:    */     catch (Exception e)
/* 171:    */     {
/* 172:295 */       rMap.put("success", Boolean.valueOf(false));
/* 173:    */       
/* 174:297 */       rMap.put("message", e.getMessage());
/* 175:    */       
/* 176:299 */       e.printStackTrace();
/* 177:    */     }
/* 178:303 */     return rMap;
/* 179:    */   }
/* 180:    */   
/* 181:    */   @RequestMapping({"/download"})
/* 182:    */   public void download(@RequestParam String filename, HttpServletRequest request, HttpServletResponse response)
/* 183:    */   {
/* 184:315 */     BufferedInputStream bis = null;
/* 185:    */     try
/* 186:    */     {
/* 187:319 */       File file = new File(URLDecoder.decode(filename, "utf-8"));
/* 188:    */       
/* 189:321 */       String mod = request.getParameter("MODULE_NO") + "/";
/* 190:    */       
/* 191:323 */       String filepath = (String)((Map)SpringContextUtil.getBean("config")).get("filepath") + mod + "/";
/* 192:    */       
/* 193:325 */       String ID = request.getParameter("ID") + "/";
/* 194:    */       
/* 195:327 */       filepath = filepath + ID;
/* 196:    */       
/* 197:329 */       filepath = filepath + CodeUtil.code(FileUtil.getBaseFileName(file)) + "." + FileUtil.getFileType(file);
/* 198:    */       
/* 199:331 */       File finalFile = new File(filepath);
/* 200:    */       
/* 201:333 */       bis = new BufferedInputStream(new FileInputStream(finalFile));
/* 202:    */       
/* 203:335 */       byte[] buff = new byte[2048];
/* 204:    */       int bytesRead;
/* 205:339 */       while (-1 != (bytesRead = bis.read(buff, 0, buff.length)))
/* 206:    */       {
/* 207:    */         //int bytesRead;
/* 208:341 */         response.getOutputStream().write(buff);
/* 209:    */       }
/* 210:    */     }
/* 211:    */     catch (Exception e)
/* 212:    */     {
/* 213:347 */       e.printStackTrace();
/* 214:    */       try
/* 215:    */       {
/* 216:352 */         if (bis != null) {
/* 217:353 */           bis.close();
/* 218:    */         }
/* 219:    */       }
/* 220:    */       catch (Exception e1)
/* 221:    */       {
/* 222:357 */         e1.printStackTrace();
/* 223:    */       }
/* 224:    */     }
/* 225:    */     finally
/* 226:    */     {
/* 227:    */       try
/* 228:    */       {
/* 229:352 */         if (bis != null) {
/* 230:353 */           bis.close();
/* 231:    */         }
/* 232:    */       }
/* 233:    */       catch (Exception e)
/* 234:    */       {
/* 235:357 */         e.printStackTrace();
/* 236:    */       }
/* 237:    */     }
/* 238:    */   }
/* 239:    */   
/* 240:    */   @RequestMapping({"/excelPage"})
/* 241:    */   public Map<String, Object> excelPage(ModelMap model, HttpServletRequest request)
/* 242:    */   {
/* 243:372 */     Map<String, Object> rMap = servce().getRMap();
/* 244:    */     try
/* 245:    */     {
/* 246:376 */       Map<String, Object> params = servce().getParams(model);
/* 247:    */       
/* 248:378 */       String mod = MapUtil.getString((Map)model.get("module"), "MODULE_NO");
/* 249:    */       
/* 250:380 */       params.put("MODULE_NO", mod);
/* 251:    */       
/* 252:382 */       model.putAll(params);
/* 253:    */       
/* 254:384 */       model.put("viewPage", "/commons/commons_excelIn.jsp");
/* 255:    */     }
/* 256:    */     catch (Exception e)
/* 257:    */     {
/* 258:388 */       rMap.put("success", Boolean.valueOf(false));
/* 259:    */       
/* 260:390 */       rMap.put("message", e.getMessage());
/* 261:    */     }
/* 262:394 */     if (logger.isDebugEnabled()) {
/* 263:396 */       logger.debug("excelIn信息：" + MapUtil.json(model));
/* 264:    */     }
/* 265:400 */     return rMap;
/* 266:    */   }
/* 267:    */   
/* 268:    */   public abstract CoreSimpleService servce();
/* 269:    */ }


/* Location:           D:\Users\Desktop\shanxi\项目\sxazmis\WEB-INF\classes\
 * Qualified Name:     com.rinsi.core.contoller.CoreSimpleController
 * JD-Core Version:    0.7.0.1
 */